﻿
@{
    ViewBag.Title = "WxMenuEdit";
}

<div class="col-sm-6" style="padding-top: 10px;">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <form class="form-horizontal m-t" id="form1">
                <div class="form-group">
                    <label class="col-sm-3 control-label">菜单名：</label>
                    <div class="col-sm-8">
                        <input id="menuName" name="menuName" minlength="2" type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">跳转地址：</label>
                    <div class="col-sm-8">
                        <input id="menuUrl" type="text" class="form-control" name="menuUrl">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">按钮类型：</label>
                    <div class="col-sm-8">
                        <select class="form-control m-b" id="menuType" name="menuType">
                            <option value="click">点击</option>
                            <option value="view">链接跳转</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-3 text-center">
                        <button id="btn_Submit" class="btn btn-primary" type="button">保存</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

@section Js{
    <script type="text/javascript">
        model = @MvcHtmlString.Create(ViewBag.Json);
        var pid = @ViewBag.Pid;
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        var validator = $("#form1").validate({
            rules: {
                menuName: {
                    required: true
                },
                menuType: {
                    required: true
                }
            },
            messages: {
                menuName: {
                    required: "请输入菜单名"
                },
                menuType: {
                    required: "请选择菜单类型"
                }
            }
        });
        $(function() {
            //dataInit();
            $("#btn_Submit").click(function() {
                if ($("#menuType").val() == "click") {
                    $("#menuUrl").rules("remove");
                    $("#menuUrl").removeClass("error");
                } else {
                    $("#menuUrl").rules("add", { required: true, url: true, messages: { required: "请输入跳转地址" } });
                }
                if (validator.form()) {
                    var parms = {
                        menuId: model.menuId,
                        menuName: $.trim($("#menuName").val()),
                        pId: model.menuId == 0 ? pid : model.pId,
                        menuUrl: $.trim($("#menuUrl").val()),
                        menuType: $("#menuType").val()
                    }
                    $.post("/WxSet/WxMenuSave", parms, function(json) {
                        if (json.result == "success") {
                            layer.msg(json.msg, { icon: 1, time: 2000 }, function(data) {
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(json.msg, { icon: 5, time: 2000 });
                        }
                    }, "json");
                }
            });

        });


    </script>
}